"""

    异步操作Postgresql

"""
import asyncio

import asyncpg
import functools
import time
from typing import Callable, Any


async def main():
    connection = await asyncpg.connect(
        host="127.0.0.1",
        port="5432",
        database="test",
        user="around",
        password="zhouwei",
    )
    version = connection.get_server_version()
    print(f"连接成功，Postgresql版本为{version}")
    await connection.close()


# asyncio.run(main())

def async_timed():
    def wrapper(func: Callable):
        @functools.wraps(func)
        async def wrapped(*args: Any, **kwargs: Any) -> Any:
            print(f"有参数{args}，{kwargs}的函数{func}开始运行")
            start = time.time()
            try:
                return await func(*args, **kwargs)
            finally:
                end = time.time()
                total = end - start
                print(f"函数{func}总共花费时间：{total}s")

        return wrapped

    return wrapper

async def delay(seconds):
    print(f"sleep for {seconds} seconds")
    await asyncio.sleep(seconds)